﻿using ArtMath.Attribute;
using ArtMath.Component.Polygon;
using ArtMath.Core.Data;
using ArtMath.Setting;
using System;
using System.ComponentModel;
using System.Drawing;

namespace ArtMath.Component.Point
{
    /// <summary>
    /// 多边形重心基类
    /// </summary>
    [Serializable]
    public abstract class BaryCenterBase : ConstructedPointBase
    {
        public BaryCenterBase(SketchPad pad, string name, PolygonBase pol, bool addToList = true) : base(pad, name, ToolTypeName.dbxzx, addToList)
        {
            OutHosts = new LineBase[1];
            Polygon = pol;
            OutlineColor = Settings.Instance.BaryCenterPointOutlineColor;
            FillColor = Settings.Instance.BaryCenterPointFillColor;
        }
        [DefaultValue(typeof(Color), "142, 53, 74")]
        public override Color OutlineColor
        {
            get
            {
                return base.OutlineColor;
            }

            set
            {
                base.OutlineColor = value;
            }
        }
        [DefaultValue(typeof(Color), "225, 107, 140")]
        public override Color FillColor
        {
            get
            {
                return base.FillColor;
            }

            set
            {
                base.FillColor = value;
            }
        }
        [MultilingualCategory("Structure"), MultilingualDisplayName("Polygon")]
        public PolygonBase Polygon
        {
            get { return OutHosts[0] as PolygonBase; }
            set
            {
                if (value is PolygonBase)
                {
                    SetLine(0, value);
                }
            }
        }
        public override PointD GetNewLocationAfterOutHostChanged(bool getXY = false)
        {
            return getXY ? Polygon.NewBaryCenter : Polygon.NewPBaryCenter;
        }
        public override void ConvertType(ToolTypeName targetType)
        {
            if (targetType != ToolType) return;
            BaryCenterBase targetPoint = null;
            SimulateDeleted(() =>
            {
                if (Pad.CoordinateType == CoordinateSystemType.PolarCoordinate)
                {
                    targetPoint = new PBaryCenter(Pad, Name, Polygon, LayerItem != null);
                }
                else
                {
                    targetPoint = new RBaryCenter(Pad, Name, Polygon, LayerItem != null);
                }
            });
            afterGenerateNewType(targetPoint);
        }
    }
}
